package com.thinkgem.jeesite.modules.euler.sdk.cmd;

import java.util.Date;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.springframework.beans.factory.annotation.Autowired;

import com.thinkgem.jeesite.modules.euler.entity.TaskStatEntity;
import com.thinkgem.jeesite.modules.euler.sdk.CommandFactory;
import com.thinkgem.jeesite.modules.euler.sdk.base.Command;
import com.thinkgem.jeesite.modules.euler.service.MonitorService;

public class MonitorBegin implements Command {

	@Autowired
	MonitorService monitorService;

	@Override
	public String getName() {
		return "begin";
	}

	@Override
	public void execute(CommandLine cmd) {
		String taskName = null;
		if (cmd.hasOption(CommandFactory.CMD_NAME)) {
			taskName = cmd.getOptionValue(CommandFactory.CMD_NAME);
		}
		Date beginDate = new Date();
		
		TaskStatEntity entity = new TaskStatEntity();
		
		entity.setTaskName(taskName);
		TaskStatEntity tmpEntity = monitorService.get(entity);
		
		if (tmpEntity != null) {
			entity = tmpEntity;
		}
		
		entity.setBeginDate(beginDate);
		entity.setTaskStatus("执行中");
		monitorService.save(entity);
	}

	@Override
	public void addOptions(Options options) {

	}

}
